//logs.js
const util = require('../../utils/util.js')
const WxParse = require("../../utils/wxParse/wxParse.js")
var app = getApp()
Page({
  data: {
    logs: [],
    aboutList: [],
    htmlText: "",
    pageTimer: "",
    typeList:[],
    pageId:'',
    imgUrl:'https://res.youth.cn/article_201808_08_082_5b6aaf1d51580.jpg',
  },
  onLoad: function (param) {
    console.log(param)
    this.setData({
      pageId: param.pageId
    })
    wx.showLoading({
      title:"正在加载"
    })
    var that = this;
    this.requestData(param.pageId)
    this.aboutList(param.pageId)
  },
  goHome: function () { // 跳首页
    wx.navigateBack()
  },
  goShare:function(){
    console.log(1)
    this.onShareAppMessage()
  },
  onShareAppMessage: function () {
    var that = this
    return {
      title: '新闻详情',
      path: '/page/news/news?id='+that.data.pageId,
      success: function (res) {
       wx.showToast({
         title: '分享成功',
         duration:1000,
       })
      },
      
    }
  },
  goDetails: function (e) { // 进入详情页
    wx.redirectTo({
      url: '../newDetails/newDetails?pageId=' + e.currentTarget.dataset.pageid
    })
  },

  //
  requestData: function (id) {
    var that = this
    var nowTime = new Date().getTime()
    app.globalData.allInfo.catid = that.data.catid;
    app.globalData.allInfo.nowTime = nowTime;
    app.globalData.allInfo.id=id;
    app.globalData.allInfo.uid = app.globalData.userInfo.uid
    var requestData = 'https://kandian.youth.cn:8181//WechatApp/Article/info.json?' + app.makeUrl(app.globalData.allInfo)
    var requestDataSign = app.makeSign(app.globalData.allInfo)

    wx.request({
      url: requestData,
      data: {
        sign: requestDataSign
      },
      success: function (res) {
        wx.hideLoading()
        that.setData({
          htmlText: res.data
        })
        that.timer(res.data.input_time)
        if (that.data.htmlText.content){
          var newString = that.data.htmlText.content.replace(/data-src/g, 'src')
        }
        var temp = WxParse.wxParse('article', 'html', newString, that, 5) // article 是自定义的变量名 必须和 template 里面的一致
      }
    })
  },
  aboutList: function (id) {// 相关推荐 
  console.log(id)
    var that = this;
    var nowTime = new Date().getTime()
    app.globalData.allInfo.nowTime = nowTime;
    app.globalData.allInfo.id = id;
    var aboutList = 'https://kandian.youth.cn:8181//WechatApp/Article/relate.json?' + app.makeUrl(app.globalData.allInfo)
    var aboutListSign = app.makeSign(app.globalData.allInfo)
    
    wx.request({
      url: aboutList,
      data: {
        sign: aboutListSign
      },
      success(res) {
        that.setData({
          aboutList: res.data.item
        })

      

      }
    })
  },
  
  timer:function(timer){
    timer = parseInt(timer)
    var date = new Date(timer * 1000);//如果date为10位不需要乘1000
      var Y = date.getFullYear() + '-';
      var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
      var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
      var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
      var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
      var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    this.setData({
      pageTimer: Y + M + D 
    })
  },







})